package com.yxp.offer;

import com.yxp.middle.Problem1008;
import com.yxp.util.TreeNode;

/**
 * @author : yang.xp
 * @date : 2021/8/19 9:48
 * @description : 剑指 Offer 27. 二叉树的镜像
 */
public class Problem27 {

    public static void main(String[] args) {
        int[] numbersA = new int[]{8, 5, 1, 7, 10, 12};
        Problem1008 problem1008 = new Problem1008();
        TreeNode treeNodeA = problem1008.bstFromPreorder(numbersA);
        Problem27 problem27 = new Problem27();
        problem27.mirrorTree(treeNodeA);
        Problem32_2 problem32_2 = new Problem32_2();
        System.out.println(problem32_2.levelOrder(treeNodeA));
    }

    public TreeNode mirrorTree(TreeNode root) {
        exchange(root);
        return root;
    }

    public void exchange(TreeNode node) {
        if (node == null) {
            return;
        }
        TreeNode tempNode = node.left;
        node.left = node.right;
        node.right = tempNode;
        exchange(node.left);
        exchange(node.right);
    }
}
